package com.rightsidetech.http.controller.agentApp.login;

import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.UpdateImageReq;
import com.rightsidetech.system.dtos.request.UpdatePhoneNoReq;
import com.rightsidetech.system.dtos.response.agent.AgentAppInfoResp;
import com.rightsidetech.system.service.SysAgentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

/**
 * @Author: yhr
 * @Date: 2021-11-08 15:13
 */
@RestController
@RequestMapping("/agentApp/agent_info")
@ShenyuSpringMvcClient(path = "/agentApp/agent_info/**")
@Api(tags = "agentApp:个人信息相关")
public class AgentAppLoginInfoController extends BaseController {
    @Resource
    private SysAgentInfoService sysAgentInfoService;

    @Log
    @Token
    @ApiOperation("个人信息")
    @GetMapping("/agentInfo")
    public ResponseData<AgentAppInfoResp> agentInfo() throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysAgentInfoService.agentInfo(loginInfoId);
    }

    @Log
    @Token
    @ApiOperation("修改手机号")
    @PostMapping("/updatePhone")
    public ResponseData updatePhone(@RequestBody UpdatePhoneNoReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysAgentInfoService.updatePhone(req,loginInfoId);
    }

    @Log
    @Token
    @ApiOperation("修改头像")
    @PostMapping("/updateHeadImg")
    public ResponseData updateHeadImg(@RequestBody UpdateImageReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        Long loginInfoId = Long.parseLong(getAttribute());
        return sysAgentInfoService.updateHeadImg(req,loginInfoId);
    }

}
